<fieldset>
	<legend>Danh sách tác giả</legend>
	<form class="well form-search">
	    <a class="btn btn-primary" href="<?php echo $this->config->base_path; ?>/librarian/author/create">Tạo tác giả</a>
        <div class="right">
            <input type="text" name="q" value="<?php echo $this->q; ?>" class="input-medium search-query">
            <button type="submit" class="btn">Tìm kiếm</button>
        </div>
    </form>
    <?php if ($this->q) { ?>
    <div class="alert alert-info">Có <strong><?php echo count($this->authors); ?></strong> kết quả tìm kiếm với từ khoá: "<strong><?php echo $this->q; ?></strong>"</div>
    <?php } ?>
	<table class="table table-striped">
        <tr>        
            <th>Tên tác giả</th>
            <th>Ngày tạo</th>
            <th>Thao tác</th>
        </tr>
        <?php foreach($this->authors as $author) { ?>
        <tr id="row-author-id-<?php echo $author['AuthorID']; ?>">
            <td><a href="<?php echo $this->config->base_path; ?>/librarian/author/edit/author_id/<?php echo $author['AuthorID']; ?>"><?php echo $author['Name']; ?></a></td>
            <td><?php echo date('d/m/Y H:i:s', $author['CreateDate']); ?></td>
            <td><a href="<?php echo $this->config->base_path; ?>/librarian/author/edit/author_id/<?php echo $author['AuthorID']; ?>">Chỉnh sửa</a> / <a href="javascript: Author.delete(<?php echo $author['AuthorID']; ?>)" onclick="return confirm('Bạn có chắc chắn muốn xoá tác giả <?php echo $author['Name']; ?>?');" >Xoá</a></td>
        </tr>
        <?php } ?>
    </table>
</fieldset>
<script type="text/javascript">
var Author = {
	'delete' : function(AuthorID){		
		$.ajax({
			url: config.base_path + '/librarian/author/delete',
			type: 'post',
			data: {
				AuthorID: AuthorID
			},
			dataType: 'json',					
			success: function(res){
				if (res.status == 0)
                {
                    Utils.Message.Error(res.message);
                }
				else
				{
				    $('#row-author-id-' + AuthorID).remove();
				}                   
			}
		});
	}
};
</script>